Overview
Single-node training is ideal for experiments and medium-scale training on one machine with multiple GPUs. OpenCLIP usestorchrun (PyTorch’s distributed launcher) for efficient multi-GPU training on a single node.
Prerequisites
- Single machine with 1 or more GPUs
- CUDA-capable GPUs (recommended: V100, A100, or newer)
- OpenCLIP installed with training dependencies
- Training data prepared in CSV or WebDataset format
Basic Single-Node Training
Single GPU Training
For single GPU training, you can use the training script directly withouttorchrun:
The
--imagenet-val argument should point to the validation set of ImageNet for zero-shot evaluation, not the training set. The val folder should contain subfolders for each class.Multi-GPU Training with torchrun
For training on multiple GPUs on a single node, usetorchrun with the --nproc_per_node flag:
--nproc_per_node 4: Number of GPUs to use (4 GPUs in this example)--batch-size 320: Per-GPU batch size (total batch size = 320 × 4 = 1280)--workers 4: Number of data loading workers per GPU--precision amp: Automatic Mixed Precision for faster training and lower memory usage
WebDataset Training Example
WebDataset format is recommended for datasets larger than 10M samples:--dataset-type webdataset: Specify WebDataset format--dataset-resampled: Enable sampling with replacement (recommended for large datasets)--train-num-samples: Total number of samples in dataset
Batch Size and Worker Configuration
Calculating Effective Batch Size
The effective batch size is:--batch-size 256(per GPU)--nproc_per_node 4(4 GPUs)--accum-freq 1(no gradient accumulation)- Effective batch size: 256 × 4 × 1 = 1024
Optimizing Worker Count
The--workers parameter controls the number of data loading processes per GPU:
- Start with 4-8 workers per GPU
- Too few workers: GPU starvation (low utilization)
- Too many workers: CPU/memory overhead
- Monitor GPU utilization and adjust accordingly
Memory Optimization
If you run out of GPU memory, try these options in order:-
Enable Mixed Precision:
-
Reduce Batch Size:
-
Enable Gradient Checkpointing:
-
Use Gradient Accumulation:
Monitoring Training
TensorBoard
Launch TensorBoard to monitor training progress:Weights & Biases (wandb)
For cloud-based experiment tracking:Both TensorBoard and wandb
You can log to both simultaneously:Zero-Shot Evaluation During Training
Automatic zero-shot evaluation on ImageNet during training:--imagenet-val: Path to ImageNet validation set--zeroshot-frequency 1: Run zero-shot eval every epoch--zeroshot-frequency 2: Run zero-shot eval every 2 epochs
Complete Training Example
Here’s a complete example training ViT-B/32 on CC12M with 4 GPUs:Advanced Configuration
Custom Learning Rate Schedule
Patch Dropout for ViT Models
Speed up Vision Transformer training by 2-3x:Gradient Clipping
Prevent gradient explosion:Model-Specific Optimizations
For Vision Transformers (ViT):Checkpointing and Resuming
Automatic Checkpointing
Checkpoints are saved automatically:Resume Training
Resume from a specific checkpoint:Save Most Recent Checkpoint Only
To save disk space, keep only the latest checkpoint:Performance Optimization
GPU Utilization
Monitor GPU usage:- Increase
--workers(data loading parallelism) - Use faster storage (NVMe SSD)
- Increase
--batch-sizeif memory allows - Ensure data is preprocessed and ready
Training Speed
Typical training speeds on A100 GPUs:Troubleshooting
Out of Memory Errors
- Reduce
--batch-size - Enable
--precision amp - Use
--grad-checkpointing - Increase
--accum-freqand reduce--batch-size
Data Loading Bottleneck
- Increase
--workers - Use faster storage (SSD vs HDD)
- Preprocess data to WebDataset format
- Check network speed if data is remote
Port Already in Use
ImageNet Validation Issues
If zero-shot evaluation fails, ensure:--imagenet-valpoints to validation set (not training set)- Directory structure is correct:
- Use the ImageNet validation prep script if needed
Example Training Scripts
Small-Scale Experiment (RN50 on CC3M)
Medium-Scale (ViT-B/32 on CC12M)
Large Model (ViT-L/14)
Next Steps
Multi-Node Training
Scale to multiple machines with torchrun or SLURM
Configuration
Explore all available training parameters
Distributed Training
Advanced distributed training techniques
Data Preparation
Prepare datasets in CSV or WebDataset format
